package com.zthz.douxing.command

import com.zthz.douxing.DataType
import com.zthz.douxing.DataVersion

import grails.validation.Validateable

/**
 * Created by zsw on 4/23/14.
 */
@Validateable
class DouXingDataVersionCommand extends DouXingCommand {

    String fileUrl
    String versionLabel
    String dataVersion
    String dataType
    String extendNote

    static constraints = {

        fileUrl nullable: false

        versionLabel nullable: false

        dataVersion nullable: false

        extendNote nullable: true,blank:true

        dataType nullable: false
    }

    protected boolean isExits(String type){

        def result = null

        switch (type){
            case "Application" :  result = DataVersion.findByDataType(DataType.Application)
                break
            case "CityName" :  result = DataVersion.findByDataType(DataType.CityName)
                break
            case "TrainSchedule" :  result = DataVersion.findByDataType(DataType.TrainSchedule)
                break
        }
        return result ? true:false
    }

}

@Validateable
class DouXingDataVersionUpdateCommand extends DouXingDataVersionCommand {



    static constraints = {

        uid nullable: false

        fileUrl nullable: true

        versionLabel nullable: true

        dataVersion nullable: true

        dataType nullable: true
    }

}

@Validateable
class DouXingDataVersionDeleteCommand extends DouXingCommand{

    static constraints ={

        uid nullable: false,blank: false

    }
}